// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 *
 * @author: yanking
 * Create time: 2022-03-18 21:52
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.DesignPattern.ChainOfResponsobility;

@SuppressWarnings("ALL")
public abstract class ProcessObject<T> {
    /**
     * 责任连锁模型 -> 递归处理数据
     */
    protected ProcessObject<T> successor;


    public void setSuccessor(ProcessObject<T> successor) {
        this.successor = successor;
    }

    public T handle(T input) {
        T r = handleWork(input);
        if (successor != null) {
            return successor.handle(r);
        }
        return r;
    }

    abstract protected T handleWork(T input);

}
